namespace Umbraco.Ecommerce.BusinessLogic.Collections
{
    using System;
    using System.Collections;
    
    
    /// <summary>
    /// Represents a collection of <see cref='store.businesslogic.ProductVariant'/> objects.
    /// </summary>
    public class ProductVariantCollection : System.Collections.ICollection
    {
        
        // Provides the base object storage used by this class
        private System.Collections.ArrayList items;
        
        // This version counter is incremented any time the collection changes.
        private int listVersion;
        
        /// <summary>
        /// Initializes a new instance of the <see cref='store.businesslogic.ProductVariantCollection'/> class.
        /// </summary>
        public ProductVariantCollection()
        {
            items = new System.Collections.ArrayList();
            listVersion = 0;
        }
        
        /// <summary>
        /// Returns a number that can be used to determine if the collection has changed since some previous
        /// reference point, since this value changes each time the collection is modified in any way.
        /// </summary>
        internal int Version
        {
            get
            {
                return listVersion;
            }
        }
        
        /// <summary>
        /// Gets the number objects contained in the collection.
        /// <summary>
        public virtual int Count
        {
            get
            {
                return items.Count;
            }
        }
        
        /// <summary>
        /// Gets a value indicating whether access to the collection is synchronized (thread-safe).
        /// <summary>
        public virtual bool IsSynchronized
        {
            get
            {
                return items.IsSynchronized;
            }
        }
        
        /// <summary>
        /// Gets an object that can be used to synchronize access to the collection.
        /// <summary>
        public virtual object SyncRoot
        {
            get
            {
                return items.SyncRoot;
            }
        }
        
        /// <summary>
        /// Returns the <see cref='store.businesslogic.ProductVariant'/> at the specified index of the <see cref='store.businesslogic.ProductVariantCollection'/>.
        /// </summary>
        /// <param name='index'>The zero-based index of the <see cref='store.businesslogic.ProductVariant'/> to locate in the collection.</param>
        /// <returns> The <see cref='store.businesslogic.ProductVariant'/> at the specified index of the collection.</returns>
        /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
        public virtual ProductVariant this[int index]
        {
            get
            {
                return ((ProductVariant)(this.items[index]));
            }
        }
        
        /// <summary>
        /// Called when an object is being inserted into the collection.
        /// </summary>
        public event ProductVariantCollectionChangedEventHandler Inserting;
        
        /// <summary>
        /// Called after an object has been inserted into the collection.
        /// </summary>
        public event ProductVariantCollectionChangedEventHandler InsertComplete;
        
        /// <summary>
        /// Called when an object is being removed from the collection.
        /// </summary>
        public event ProductVariantCollectionChangedEventHandler Removing;
        
        /// <summary>
        /// Called after an object has been removed from the collection.
        /// </summary>
        public event ProductVariantCollectionChangedEventHandler RemoveComplete;
        
        /// <summary>
        /// Called when the collection is being cleared.
        /// </summary>
        public event ProductVariantCollectionClearedEventHandler Clearing;
        
        /// <summary>
        /// Called after the collection has been cleared.
        /// </summary>
        public event ProductVariantCollectionClearedEventHandler ClearComplete;
        
        /// <summary>
        /// Internal method called whenever the collection changes to increment the Version property.
        /// </summary>
        private void IncrementVersion()
        {
            listVersion = (listVersion + 1);
        }
        
        /// <summary>
        /// Returns a <see cref='System.Collections.IEnumerator'/> object that can be used to enumerate
        /// the entire collection.
        /// </summary>
        public virtual System.Collections.IEnumerator GetEnumerator()
        {
            return items.GetEnumerator();
        }
        
        /// <summary>
        /// Copies the elements of this store.businesslogic.ProductVariantCollection to a System.Array, starting at a particular System.Array index.
        /// <summary>
        public virtual void CopyTo(System.Array array, int index)
        {
            items.CopyTo(array, index);
        }
        
        /// <summary>
        /// Adds the specified <see cref='store.businesslogic.ProductVariant'/> to the <see cref='store.businesslogic.ProductVariantCollection'/> collection.
        /// </summary>
        /// <returns>The position into which the new element was inserted.</returns>
        public virtual int Add(ProductVariant value)
        {
            if ((this.Inserting != null))
            {
                this.Inserting(this, value);
            }
            this.IncrementVersion();
            int retVal = items.Add(value);
            if ((this.InsertComplete != null))
            {
                this.InsertComplete(this, value);
            }
            return retVal;
        }
        
        /// <summary>
        /// Removes the specified <see cref='store.businesslogic.ProductVariant'/> from the <see cref='store.businesslogic.ProductVariantCollection'/> collection.
        /// </summary>
        public virtual void Remove(ProductVariant value)
        {
            if ((this.Removing != null))
            {
                this.Removing(this, value);
            }
            this.IncrementVersion();
            items.Remove(value);
            if ((this.RemoveComplete != null))
            {
                this.RemoveComplete(this, value);
            }
        }
        
        /// <summary>
        /// Removes the <see cref='store.businesslogic.ProductVariant'/> object at the specified index from the <see cref='store.businesslogic.ProductVariantCollection'/> collection.
        /// </summary>
        public virtual void RemoveAt(int index)
        {
            object obj = items[index];
            this.Remove(((ProductVariant)(obj)));
        }
        
        /// <summary>
        /// Inserts a <see cref='store.businesslogic.ProductVariant'/> object into the <see cref='store.businesslogic.ProductVariantCollection'/> collection at the specified position.
        /// </summary>
        /// <param name='index'>The zero-based index at which value should be inserted.</param>
        /// <param name='value'>The store.businesslogic.ProductVariant to insert into the <see cref='store.businesslogic.ProductVariantCollection'/> collection.</param>
        public virtual void Insert(int index, ProductVariant value)
        {
            if ((this.Inserting != null))
            {
                this.Inserting(this, value);
            }
            this.IncrementVersion();
            items.Insert(index, value);
            if ((this.InsertComplete != null))
            {
                this.InsertComplete(this, value);
            }
        }
        
        /// <summary>
        /// determines whether the <see cref='store.businesslogic.ProductVariantCollection'/> collection contains a specific <see cref='store.businesslogic.ProductVariant'/> object.
        /// </summary>
        /// <param name='value'>The store.businesslogic.ProductVariant object to locate in the <see cref='store.businesslogic.ProductVariantCollection'/> collection.</param>
        /// <returns>True if the System.Object is found in the collection; otherwise, False.</returns>
        public virtual bool Contains(ProductVariant value)
        {
            return items.Contains(value);
        }
        
        /// <summary>
        /// Removes all items from the collection.
        /// </summary>
        public virtual void Clear()
        {
            if ((this.Clearing != null))
            {
                this.Clearing(this);
            }
            this.IncrementVersion();
            items.Clear();
            if ((this.ClearComplete != null))
            {
                this.ClearComplete(this);
            }
        }
        
        /// <summary>
        /// Creates a shallow copy of the collection.
        /// </summary>
        public virtual ProductVariantCollection Clone()
        {
            ProductVariantCollection obj = new ProductVariantCollection();
            obj.items = ((System.Collections.ArrayList)(items.Clone()));
            obj.listVersion = this.listVersion;
            return obj;
        }
        
        /// <summary>
        /// Defines the type of event that is called whenever a new object is inserted into or removed from the store.businesslogic.ProductVariantCollection collection.
        /// </summary>
        public delegate void ProductVariantCollectionChangedEventHandler(object sender, ProductVariant value);
        
        /// <summary>
        /// Defines the type of event that is called whenever the collection is cleared.
        /// </summary>
        public delegate void ProductVariantCollectionClearedEventHandler(object sender);
    }
}

